package com.cserver.pro.utils;


import java.util.concurrent.*;

public class ThreadTest {
    public static void main(String[] args) throws InterruptedException {
        /**
         * 创建线程池的方法:
         * 1.通过newSingleThreadExecutor进行创建线程池为1的线程池
         */
//        ExecutorService executorService= Executors.newSingleThreadExecutor();
//        Thread thread1=new Te("张三");
//        executorService.execute(thread1);
//        Thread thread2=new Te("李四");
//        executorService.execute(thread2);
//        executorService.shutdown();

//        ThreadFactory threadFactory=new ThreadFactory() {
//            @Override
//            public Thread newThread(Runnable r) {
//                r.
//                return null;
//            }
//        };

//        ThreadPoolExecutor es = new ThreadPoolExecutor(1, 1, 200, TimeUnit.MILLISECONDS,
//                new ArrayBlockingQueue<Runnable>(5));

        ExecutorService es=Executors.newFixedThreadPool(4);
        Thread thread1=new Te("张三");
        es.execute(thread1);
        Thread thread2=new Te("李四");
        es.execute(thread2);
        es.shutdown();



//        Thread thread2=new Te("李四");
//        Thread thread3=new Te("王五");
//
////        thread1.start();
//        thread2.start();
//        thread3.start();





    }

}
 class  Te extends Thread{

   // static int count =1;
    public Te(String name){
        super(name);
    }
    @Override
     public void run() {

        for (int i=0;i<10;i++) {

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("-======>"+this.getName()+i);

        }

    }
}